<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        img{
            position: absolute;
            left: 0;
            top: 0;
            right: 0;
            bottom: 0;
            margin: auto;
            display:none;
        }
    </style>
    <script src="newAjax6.js"></script>
    <script>
        window.onload=function(){
            var oBtn=document.getElementById('btn');
            var oImg=document.getElementsByTagName('img')[0];
            var url='post.php';

            oBtn.onclick=function(){
                var data=ajax({
                    url:url,
                    type:'post',
                    data:{
                        a:122,
                        b:100
                    },
                    loading:function(){
                        document.body.style.background='#000';
                        oImg.style.display='block';
                    },
                    time:4,
                    success:function(str){
                        console.log(str);
                        document.body.style.background='#fff';
                        oImg.style.display='none';
                    }
                })
            };

        }
    </script>
</head>
<body>
    <input type="button" value="按钮" id="btn">
    <img src="loading.gif" alt="">
</body>
</html>